﻿using System;
using System.Windows;

namespace DotNetImage.Imaging.Filters
{
    public class OffsetFilter : FilterBase
    {
        public Point[,] Offset { get; set; }

        protected override void PrepareData(DotNetImage bmp)
        {
            bmp.CreatePixelCopy();
        }

        protected override void ProcessPixel(ref Pixel pix, uint x, uint y)
        {
            int xOffset = (int)Offset[x, y].X;
            int yOffset = (int)Offset[x, y].Y;

            if (y + yOffset >= 0 && y + yOffset < nHeight && x + xOffset >= 0 && x + xOffset < nWidth)
            {
                // Take the pixel from offset and apply to the current one
                Pixel offsetPixel = Subject.GetPreservedPixel((int)x + xOffset, (int)y + yOffset);
                pix = offsetPixel;
            }
        }
    }
}
